home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * © Copyright 1991, Rob Glanville
- *
- * by Rob Glanville
- *
- * 8 May 91
- *
- * robix.c - Super debugger
- *
- */
-
- #include "robix.h"
- #include <stdio.h>
- #include <Slots.h>
- #include <OSUtils.h>
-
- /************************************* Defines ***********************************************/
-
- #define SONIC 0x00900000
- #define ENetAddress 0x00700000
- #define ENet1 0x00 /* Logical label for a logical slot */
- #define ENet2 0x01 /* Logical label for a logical slot */
- #define Command 0x400 /* Channel Command byte */
- #define Flags 0x401 /* Channel flags */
- #define Count 0x402 /* Count word */
- #define BufferPtr 0x404 /* Address pointer */
- #define PBYTE *(unsigned char *) /* Used for physical address casting */
- #define PWORD *(unsigned short *) /* Used for physical address casting */
- #define PLONG *(unsigned long *) /* Used for physical address casting */
- #define ResetMCP 0x00F00000
- #define StartMCP 0x00C00000
- #define TxBuffer 0x008000 // Transmit buffer
- #define RxBuffer 0x00A000 // Receive buffer area 1
-
- /* Flag bits */
- #define F_ready 0x80 /* Ready */
- #define F_datachain 0x40 /* DataChain */
- #define F_update 0x20 /* Update */
- #define F_interrupt 0x10 /* Interrupt */
- #define F_timer 0x08 /* TimerInt */
- #define F_aborted 0x04 /* Aborted */
- #define F_overrun 0x02 /* Overrun */
- #define F_size 0x01 /* 0=byte, 1=word */
-
- /************************************* Variables *********************************************/
-
- UBYTE CommandLine[256]; /* Input buffer */
- UBYTE delimiter; /* Delimiter between arguments */
- UBYTE AsciiBuf[19]; /* A buffer for output */
- UBYTE Argument[0x80]; /* The arguments go here one by one */
- UBYTE TabSize; /* Size of tab stops */
- UBYTE origMMUMode; /* The original MMU mode */
- UBYTE RobSlot;
-
- UWORD ArgSize; /* Argument size */
- UWORD CPointer; /* Command pointer */
- UWORD slotPtr; /* A logical index to the slot where 1=9 */
-
- ULONG CommandIndex; /* The index into command buffer */
- ULONG number; /* A place for all numbers input */
- ULONG SlotMngrID; /* Slot manager ID */
- ULONG InfoPointer; /* Slot Information pointer */
- ULONG BufPtr; /* Alias buffer pointer for unions */
- ULONG RobBase;
-
- ilong err; /* Standard error code for Macintosh */
- ULONG slot24Bit[6]; /* 24 bit slot addresses for first megabyte */
- UBYTE *slotBases[6]; /* 32 bit slot addresses for above 1MB */
- ULONG slotCount; /* Number of active slots */
-
- /*
- * Only portions of this structure are used, the rest are just place holders
- */
- struct {
- ULONG a,b,c,d,e,f,g,h,i;
- UWORD j,k,spCatagory,spCType,spDrvrSW,spDrvrHW;
- UBYTE p,spSlot,spID,s,t,u,v,w;
- } SlotBlock;
-
- /* Transmit buffer */
- struct {
- UBYTE Destination[6];
- UBYTE Source[6];
- UWORD Length;
- UBYTE Buffer[1500];
- UWORD CRCPad;
- } TxPacket;
-
- /* Receive buffer */
- struct {
- UBYTE Destination[6];
- UBYTE Source[6];
- UWORD Length;
- UBYTE Buffer[1500];
- UWORD CRC;
- } RxPacket;
-
- /************************************* Constants *********************************************/
-
- UBYTE Digits[] = {"0123456789ABCDEF"};
- UBYTE Delimiters[] = {0x09,0x0a,0x1b,0x20,0x21,0x22,0x23,0x24,0x25,0x26,
- 0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x3a,
- 0x3b,0x3c,0x3d,0x3e,0x40,0x5b,0x5c,0x5d,0x5e,0x5f,
- 0x00,0x60,0x7b,0x7c,0x7d,0x7e,0x7f,0x3f,0x0d};
-
- struct {
- UBYTE Address[6]; /* Slot 9 is another type of Ethernet card */
- } Node [5] = {0x10,0x00,0xE0,0x28,0x08,0x77, /* Slot A card */
- 0x10,0x00,0xE0,0x28,0x03,0x40, /* Slot B card */
- 0x10,0x00,0xE0,0x28,0x08,0x77, /* Slot A card */
- 0x10,0x00,0xE0,0x28,0x08,0xEB, /* Slot D card */
- 0x10,0x00,0xE0,0x28,0x06,0xF9};/* Slot E card */
-
- /************************************* Externals *********************************************/
-
- extern UWORD GetWord(UWORD *);
- extern void PutWord(UWORD *,UWORD);
- extern UBYTE SONICMenu();
- extern BEGIN();
- extern BuildPacket(UBYTE,UBYTE,UWORD);
-
- /************************************* Routines **********************************************/
-
- void ReportError(err) ilong err; {
- switch(err) {
- case 0x00 :
- printf("No error\n");
- break;
- case -344 :
- printf("No resource available\n");
- break;
- default :
- printf("Internal program error, Undefined err number = %-d\n",err);
- break;
- }
- }
-
- void SyntaxError() {
- printf("Syntax error\n");
- }
-
- unsigned char getch() {
- unsigned char character;
- do {
- character = getchar();
- } while (character == 0xff);
- return(character);
- }
-
- void LineIn() {
- UBYTE character,exit;
- UWORD index,TabSpace;
- if (delimiter == CR) {
- CommandIndex = Null;
- exit = False;
- CPointer = Null;
- do {
- character = getch();
- if (character == Rubout) {
- if (CommandIndex > 0) {
- putchar(Rubout);
- putchar(Blank);
- putchar(Rubout);
- CommandIndex--;
- }
- }
- else if (character == CR) {
- putchar(CR);
- CommandLine[CommandIndex++] = CR;
- exit = True;
- }
- else if (character == Tab) {
- TabSpace = TabSize - ((CommandIndex+1) % TabSize);
- for (index=0;index<TabSpace;index++) {
- putchar(Blank);
- CommandLine[CommandIndex++] = Blank;
- }
- }
- else {
- /* putchar(character); */
- CommandLine[CommandIndex++] = character;
- }
- } while (!exit);
- }
- else delimiter = CR;
- }
-
- void Upper(character) UBYTE *character; {
- if ((*character >= 'a') && (*character <= 'z')) *character -= Blank;
- }
-
- void ScanDelimiters() {
- UWORD index;
- UBYTE found;
- do {
- found = False;
- for (index=0;index<sizeof(Delimiters)-2;index++) {
- if (CommandLine[CPointer] == Delimiters[index]) found = True;
- }
- if (found) CPointer++;
- } while (found);
- }
-
- void getarg() {
- UWORD index,ArgPtr;
- UBYTE found;
- ArgPtr = Null;
- do {
- found = False;
- for (index=0;index<sizeof(Delimiters);index++) {
- if (CommandLine[CPointer] == Delimiters[index]) {
- delimiter = Delimiters[index];
- if (delimiter != CR) CPointer++;
- found = True;
- break;
- }
- }
- if (!found) Argument[ArgPtr++] = CommandLine[CPointer++];
- } while (!found);
- Argument[ArgPtr] = Null;
- ArgSize = ArgPtr;
- }
-
- UWORD GetValue() {
- UBYTE found;
- UWORD index,loop;
- if (delimiter == ',') return(False);
- found = False;
- number = Null;
- do {
- getarg(); /* Get one argument from the command line */
- if (ArgSize) {
- /* Check for all digits in the argument */
- for (index=0;index<ArgSize;) {
- Upper(&Argument[index]);
- found = False;
- for (loop=0;loop<0x10;loop++) {
- if (Argument[index] == Digits[loop]) {
- Argument[index] = loop;
- found = True;
- break;
- }
- }
- if (!found) break;
- else index++;
- }
- /* Convert ascii to hex */
- if (found) for (index=0;index<ArgSize;index++) {
- number = ((number * 0x10) + Argument[index]);
- }
- }
- } while ((!found) && (delimiter != CR) && (delimiter != ','));
- return(found);
- }
-
- void nibble(data) UBYTE data; {
- if (data > 9) putchar(data + '7');
- else putchar(data + '0');
- }
-
- void byteout(data) UBYTE data; {
- nibble((data / 0x10) & 0x0f);
- nibble(data & 0x0f);
- }
-
- void wordout(data) UWORD data; {
- byteout((UBYTE)(data / 0x100) & 0xff);
- byteout((UBYTE)data & 0xff);
- }
-
- void longout(data) ULONG data; {
- wordout((UWORD)(data / 0x10000) & 0xffff);
- wordout((UWORD)data & 0xffff);
- }
-
- void crlf() { printf("\n"); }
-
- /************************************* Commands *********************************************/
-
- UWORD AlterMemory() {
- ULONG Address;
- UBYTE databyte,origMMUMode;
- if (!GetValue()) return(True);
- Address = number;
- origMMUMode = true32b;
- if (GetValue()) {
- SwapMMUMode(&origMMUMode);
- do {
- *(UBYTE *)Address++ = number;
- } while (GetValue());
- SwapMMUMode(&origMMUMode);
- return(False);
- }
- else while(True) {
- longout(Address);
- putchar(Blank);
- SwapMMUMode(&origMMUMode);
- databyte = *(UBYTE *)Address;
- SwapMMUMode(&origMMUMode);
- byteout(databyte);
- putchar('-');
- LineIn();
- ScanDelimiters();
- if (!GetValue()) return(False);
- SwapMMUMode(&origMMUMode);
- *(UBYTE *)Address++ = number;
- SwapMMUMode(&origMMUMode);
- }
- }
-
- UWORD AlterWordMemory() {
- UBYTE origMMUMode;
- UWORD dataword;
- ULONG Address;
- if (!GetValue()) return(True);
- Address = number;
- origMMUMode = true32b;
- if (GetValue()) {
- SwapMMUMode(&origMMUMode);
- do {
- *(UWORD *)Address = number;
- Address += 2;
- } while (GetValue());
- SwapMMUMode(&origMMUMode);
- }
- else {
- longout(Address);
- putchar(Blank);
- SwapMMUMode(&origMMUMode);
- dataword = *(UWORD *)Address;
- SwapMMUMode(&origMMUMode);
- wordout(dataword);
- crlf();
- }
- return(False);
- }
-
- UWORD DisplayMemory() {
- ULONG Start,Length,index,Aindex,Sindex;
- register UBYTE databyte;
- UBYTE origMMUMode;
- if (!GetValue()) return(True);
- Start = number;
- if (GetValue()) Length = number;
- else Length = 0x10;
- if (Length == 0) Length = 1;
- origMMUMode = true32b;
- index = Null;
- Aindex = Null;
- do {
- if ((index % 0x10) == 0x00) longout(Start);
- putchar(Blank);
- SwapMMUMode(&origMMUMode);
- databyte = *(UBYTE *)Start;
- SwapMMUMode(&origMMUMode);
- if ((databyte >= Blank) && (databyte <= 0x7e)) AsciiBuf[Aindex++] = databyte;
- else AsciiBuf[Aindex++] = '.';
- Start++;
- byteout(databyte);
- if ((index % 0x10) == 0x0f) {
- AsciiBuf[16] = CR;
- AsciiBuf[17] = Null;
- putchar(Blank);
- putchar(Blank);
- printf("%s",AsciiBuf);
- Aindex = Null;
- }
- } while (++index<Length);
- if ((index % 0x10) != Null) {
- Sindex = 0x10 - (index % 0x10);
- for (index=0;index<Sindex;index++) printf(" ");
- AsciiBuf[Aindex] = Null;
- printf(" ");
- printf("%s",AsciiBuf);
- crlf();
- }
- return(False);
- }
-
- UWORD FillMemory() {
- ULONG Start,Length,Value,index;
- UBYTE increment,origMMUMode;
- if (!GetValue()) return(True);
- Start = number;
- if (!GetValue()) return(True);
- Length = number;
- if (Length == 0) Length = 1;
- if (!GetValue()) {
- if (Argument[0] == 'I') {
- increment = True;
- Value = 0;
- }
- else return(True);
- }
- else {
- increment = False;
- Value = number;
- }
- origMMUMode = true32b;
- SwapMMUMode(&origMMUMode);
- for (index=0;index<Length;index++) {
- *(UBYTE *)Start++ = Value;
- if (increment) Value++;
- }
- SwapMMUMode(&origMMUMode);
- return(False);
- }
-
- UBYTE WaitForDone(UBYTE slot) {
- ULONG timer = 0x80000,junk;
- junk = (slot24Bit[slot] + Flags);
- while ((PBYTE (slot24Bit[slot] + Flags) & F_ready) && (--timer));
- if (timer) return (False); /* No problem */
- else return(True); /* Timeout */
- }
-
- void TransmitData(ULONG buffer, UWORD length, UBYTE slot) {
- PBYTE (slot24Bit[slot] + Command) = 0x02; /* Transmit command */
- PWORD (slot24Bit[slot] + Count) = length; /* Set length */
- PLONG (slot24Bit[slot] + BufferPtr) = buffer; /* Set address */
- PBYTE (slot24Bit[slot] + Flags) = 0x80; /* Set ready bit */
- }
-
- void ReceiveData(ULONG buffer, UWORD length, UBYTE slot) {
- PBYTE (slot24Bit[slot] + Command) = 0x04; /* Receive command */
- PWORD (slot24Bit[slot] + Count) = length; /* Set length */
- PLONG (slot24Bit[slot] + BufferPtr) = buffer; /* Set address */
- PBYTE (slot24Bit[slot] + Flags) = 0x80; /* Set ready bit */
- }
-
- void TestCards() {
- ULONG loopCount;
- UBYTE txerror,rxerror;
- if (GetValue()) loopCount = number;
- else loopCount = 1;
- while (loopCount--) {
- ReceiveData(0x0000A000,1500,ENet2);
- TransmitData(0x00008000,1500,ENet1);
- txerror = WaitForDone(ENet1); /* Wait for transmiter to finish */
- rxerror = WaitForDone(ENet2); /* Wait for receiver to finish */
- if (rxerror) {
- printf("Receiver timeout\n");
- break;
- }
- if (txerror) {
- printf("Transmitter timeout\n");
- break;
- }
- }
- }
-
- /*
- * Reset the card
- * Copy code from main Mac memory into John Galt local memory
- * Remove reset
- */
- #define Miscompare 'M'
- #define Timeout 'T'
- #define RunFlag 0x4f0
- UBYTE Download(UBYTE slot,UBYTE *CodePointer,ULONG Length) {
- UBYTE theMMUMode = true32b; /* Set the temproary mode */
- UBYTE error = Null;
- UWORD bucket; /* A place for dummy read */
- ULONG timer;
- volatile UBYTE *Memory = (UBYTE *)slotBases[slot]+0x1000;/* Point to 0xFn010000 for download */
- SwapMMUMode( &theMMUMode ); /* Set MMU to 32 bit mode */
- *(UWORD *)(slotBases[slot] + ResetMCP) = 0x0000;/* Reset the card */
- *(UWORD *)(slotBases[slot] + 0) = 0x0002; /* Set the interrupt stack address */
- *(UWORD *)(slotBases[slot] + 2) = 0x0000; /* Set the interrupt stack address */
- *(ULONG *)(slotBases[slot] + 4) = 0x1000; /* Set the starting address */
- while (Length--) {
- *Memory = *CodePointer; /* Zap Memory */
- if (*Memory++ != *CodePointer++) { /* Compare source and destination */
- error = Miscompare;
- break;
- }
- }
- PLONG (slotBases[slot] + RunFlag) = 'RobG'; /* Set ready indicator to almost anything */
- bucket = *(UWORD *)(slotBases[slot] + StartMCP);/* Remove the reset and let it live */
- timer = 0x10000; /* Set the timeout timer, This is a very long time */
- while ((PLONG (slotBases[slot] + RunFlag) != 'Loop') && (--timer));/* Wait for ready indicator */
- SwapMMUMode( &theMMUMode ); /* Set MMU back to 24 bit mode */
- if (timer == Null) error = Timeout;
- return(error); /* Return the errors */
- }
-
- UBYTE SetUpENetCard(UBYTE slot) {
- UBYTE error = 0;
- UBYTE *theStartLabel = ( ULONG * )BEGIN;
- ULONG realStart;
- realStart = theStartLabel;
- realStart += 2;
- realStart = *(ULONG *)(realStart);
- (ULONG)theStartLabel = realStart;
- error = Download(slot,theStartLabel,0x2000);
- return(error);
- }
-
- void MakeTxPacket(UBYTE slot,UBYTE station,UWORD length) {
- UWORD index;
- UBYTE *SPtr,*DPtr;
- /* Build a packet in local memory */
- for (index=0;index<6;index++) {
- TxPacket.Destination[index] = Node[station].Address[index];
- TxPacket.Source[index] = Node[slot].Address[index];
- }
- if (length > 1500) length = 1500;
- else if (length < 64) length = 64;
- TxPacket.Length = length;
- for (index=0;index<length;index++) {
- TxPacket.Buffer[index] = index;
- }
- /* Copy packet to ENet card memory */
- SPtr = (UBYTE *)&TxPacket;
- DPtr = (UBYTE *)(slotBases[slot] + TxBuffer);
- length += 14; /* Add in the addresses and length fields */
- origMMUMode = true32b;
- SwapMMUMode(&origMMUMode);
- for (index=0;index<length;index++) {
- *DPtr++ = *SPtr++;
- }
- SwapMMUMode(&origMMUMode);
- }
-
- void LookForNuBusENet() {
- UBYTE err;
- UWORD index;
- for (index=0;index<6;index++) slot24Bit[index] = False; /* Clear the Pointers */
- slotCount = Null; /* Clear the count */
- SlotBlock.spCatagory = 0x000A;
- SlotBlock.spCType = 0x0001;
- SlotBlock.spDrvrSW = 0xFFFF;
- SlotBlock.spDrvrHW = 0x0002;
- SlotBlock.spSlot = 0x08;
- SlotBlock.spID = 0x80;
- do {
- err = SNextTypeSRsrc((SpBlockPtr)&SlotBlock);
- if (err == Null) {
- slot24Bit[slotCount] = SlotBlock.spSlot * 0x00100000;
- (ULONG)slotBases[slotCount++] = (0xF0000000 + (SlotBlock.spSlot * 0x01000000));
- }
- } while (err == Null);
- for (index=0;index<slotCount;index++) { /* Lets display them for debug */
- err = SetUpENetCard(index);
- if (err) printf("Ethernet card %d has error %02X\n",index,err);
- else {
- MakeTxPacket(index,index + 1,1500); /* Build a packet */
- printf("Ethernet card %d has been initialized\n",index);
- printf("Slot base is %lx\n",slotBases[index]);
- }
- }
- }
-
- void Help() {
- printf("?) Print this menu\n");
- printf("A) Alter memory\n");
- // printf("B) \n");
- // printf("C) \n");
- printf("D) Display memory\n");
- // printf("E) \n");
- printf("F) Fill memory\n");
- // printf("G) \n");
- // printf("H) \n");
- printf("I) Alter or display word memory\n");
- // printf("J) \n");
- // printf("K) \n");
- // printf("L) \n");
- printf("M) Go to SONIC menu\n");
- // printf("N) \n");
- // printf("O) \n");
- // printf("P) \n");
- printf("Q) Quit ROBIX\n");
- // printf("R) \n");
- // printf("S) \n");
- printf("T) Test cards using channel commands\n");
- // printf("U) \n");
- // printf("V) \n");
- // printf("W) \n");
- // printf("X) \n");
- // printf("Y) \n");
- // printf("Z) \n");
- }
-
- /************************************* Main Loop ********************************************/
-
- void main() {
- UBYTE Exit,ExitMode;
- delimiter = CR;
- TabSize = 8;
- Exit = False;
- printf("ROBIX\n");
- LookForNuBusENet(); /* Get the configuration */
- while (!Exit) {
- if (delimiter == CR) putchar('>');
- LineIn();
- ScanDelimiters(); /* Point to first non Blank */
- Upper(&CommandLine[CPointer]);
- switch(CommandLine[CPointer++]) {
- case '?' :
- Help();
- break;
- case CR :
- break;
- case 'A' :
- if (AlterMemory()) SyntaxError();
- break;
- case 'B' :
- BuildPacket(ENet1,ENet2,0x1500); /* Build a packet for ENet 1 */
- BuildPacket(ENet2,ENet1,0x1500); /* Build a packet for ENet 2 */
- break;
- case 'C' :
- break;
- case 'D' :
- if (DisplayMemory()) SyntaxError();
- break;
- case 'E' :
- break;
- case 'F' :
- if (FillMemory()) SyntaxError();
- break;
- case 'G' :
- break;
- case 'H' :
- break;
- case 'I' :
- if (AlterWordMemory()) SyntaxError();
- break;
- case 'J' :
- break;
- case 'K' :
- break;
- case 'L' :
- break;
- case 'M' :
- ExitMode = SONICMenu();
- if (ExitMode == 'Q') Exit = True;
- break;
- case 'N' :
- break;
- case 'O' :
- break;
- case 'P' :
- break;
- case 'Q' :
- Exit = True;
- printf("Bye...\n");
- break;
- case 'R' :
- break;
- case 'S' :
- break;
- case 'T' :
- TestCards();
- break;
- case 'U' :
- break;
- case 'V' :
- break;
- case 'W' :
- break;
- case 'X' :
- break;
- case 'Y' :
- break;
- case 'Z' :
- break;
- default :
- printf("Unknown command\n");
- delimiter = CR;
- break;
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-